#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, R;
    cin >> n >> R;

    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        cin >> b[i];

    priority_queue<long long> pq; 
    long long total = 0;

    for (int i = 0; i < n; ++i)
    {
        long long d = a[i] - b[i];
        total += d * d;
    
        if (d > 0)
        {
            pq.push(2 * d - 1); 
        }
        else if (d < 0)
        {
            pq.push(-2 * d - 1); 
        }
    }

    
    while (R-- > 0 && !pq.empty())
    {
        long long reduce = pq.top();
        pq.pop();

        if (reduce <= 0)
            break; 

        total -= reduce;

        
        long long next_reduce = reduce - 2;
        if (next_reduce > 0)
        {
            pq.push(next_reduce);
        }
    }

    cout << total << endl;

    return 0;
}
